
/// CGAL POLYHEDRON_3 VIEWER source code
/// by Alvaro Cuno, LCG-COPPE-UFRJ
/// bugs? email-me: alvaroecp@gmail.com
/// November, 2007

#ifndef __MESH_H__
#define __MESH_H__

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/HalfedgeDS_vector.h>
#include <CGAL/IO/Polyhedron_iostream.h>

#include <vector>
#include <list>

#include "meshItems.h"
#include "../typedefs.h"

typedef CGAL::Polyhedron_3<Kernel, My_items,
                           CGAL::HalfedgeDS_vector>      Polyhedron; // A simple Polyhedron
   
using namespace std;
   
class Mesh : public Polyhedron {
   
public:
   Mesh();
   Mesh(const char* filename);
   ~Mesh();
   
   unsigned nvertices() const { return _nvertices; }
   unsigned nfaces()    const { return _nfaces; }
   
   void loadShape(const char *filename);
   void saveShapeOFF(const char *filename);
   
   /// Reads an off model into a polyhedron data structure and returns it
   /// @param filename Name of the file containing model
   /// @return pointer to newly read model or 0 if unsuccessful
   static Mesh* load_off (const char *filename);
   
protected:
   
   /// Computes auxiliar data 
   void auxiliarData();
   void buildFacesIndices();
   
   /// This function sets the minimum and maximum points of the model
   /// These two points will edited to be represent a cube
   void limits();
   
   /// This function centers the model at the origin and
   /// rescales the vertex positions by a scale factor 
   /// @param factor the uniform scale factor. 
   /// The value 2 means a scale between [(-1,-1,-1) (1,1,1)]
   void centerAndScale(Number factor=2.0);
   
public:
   vector<unsigned>     faces;
   Number               mincoo[3];     /// minimum point coordinates
   Number               maxcoo[3];     /// maximum point coordinates
   
protected:
   unsigned             _nvertices;    /// nro of vertices
   unsigned             _nfaces;       /// nro of faces
};

typedef Mesh::Vertex_iterator                                Vertex_iterator;
typedef Mesh::Face_iterator                                  Face_iterator;
typedef Mesh::Facet_iterator                                 Facet_iterator;
typedef Mesh::Halfedge_iterator                              Halfedge_iterator;
typedef Mesh::Face_handle                                    Face_handle;
typedef Mesh::Vertex_handle                                  Vertex_handle;
typedef Mesh::Halfedge_handle                                Halfedge_handle;

#endif
